package eBrain.model;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;

import eBrain.beans.Bid;
import eBrain.beans.Item;
import eBrain.beans.User;
import eBrain.model.DataManager;

public class BidWorker {
	
	private Item item = new Item();
	private User user = new User();
	private DataManager dataManager = null;
	private double bidvalue; 
	
	public BidWorker(Item item, User user, DataManager datamanager, Double bidvalue){
		this.item = item;
		this.user = user;
		this.dataManager = datamanager;
		this.bidvalue = bidvalue;
	}
	
	public boolean validateBid(){
		Bid maxbid = dataManager.getMaxBidForItem(item.getId());
		if(item.getEnd().before(new Date(System.currentTimeMillis()))){
			return false;
		}
			if (bidvalue<(maxbid.getBidValue()+0.5)) {
				return false;
			}
			return true;
	}
	public double getMinBidValue(){
		Bid maxbid = dataManager.getMaxBidForItem(item.getId());
		 return	maxbid.getBidValue()+0.5;
	}
	
	public Bid getNewMaxBid(){
		Bid bid = new Bid();
		bid.setUserId(user.getUser_id());
		bid.setItemId(item.getId());
		bid.setBidValue(bidvalue);
		bid.setTimestamp(new Timestamp(System.currentTimeMillis()));
		return bid;
	}
}
